package com.shao.app.controller;

import com.shao.app.entity.Order;
import com.shao.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author PaoFu
 */
@RestController
public class OrderController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户钱包金额变动明细接口
     * @param userId
     * @return
     */
    @GetMapping("/user/{userId}/orders")
    public List<Map<String, Object>> getOrderHistory(@PathVariable Long userId) {
        List<Map<String, Object>> response = new ArrayList<>();
        List<Order> orders = userService.getOrderHistory(userId);
        for (Order order : orders) {
            Map<String, Object> orderMap = new HashMap<>();
            orderMap.put("id", order.getId());
            orderMap.put("amount", order.getAmount());
            orderMap.put("status", order.getStatus());
            response.add(orderMap);
        }
        return response;
    }
}
